package com.yongcheon.sms_manager.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by yongcheon on 2014-11-26.
 */
public class SpamDBHelper extends SQLiteOpenHelper {
    private static final int DATABASE_VERSION = 11;
    private static final String DATABASE_NAME = "spamManager";

    public SpamDBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE spam_sms (_id INTEGER PRIMARY KEY,"+
                                        "thread_id INTEGER,"+
                                        "address TEXT,"+
                                        "person INTEGER,"+
                                        "date INTEGER,"+
                                        "protocol INTEGER,"+
                                        "read INTEGER DEFAULT 0,"+
                                        "status INTEGER DEFAULT -1,"+
                                        "type INTEGER,"+
                                        "reply_path_present INTEGER,"+
                                        "subject TEXT,"+
                                        "body TEXT,"+
                                        "service_center TEXT,"+
                                        "locked INTEGER DEFAULT 0,"+
                                        "sub_id INTEGER DEFAULT 0,"+
                                        "error_code INTEGER DEFAULT 0,"+
                                        "seen INTEGER DEFAULT 0," +
                                        "spam_desc TEXT," +
                                        "spam_category TEXT)");

        db.execSQL("CREATE TABLE spam_phone (_id INTEGER PRIMARY KEY,"+
                                        "number TEXT,"+
                                        "voicemail_uri TEXT,"+
                                        "features INTEGER,"+
                                        "new INTEGER,"+
                                        "formatted_number TEXT,"+
                                        "numbertype TEXT,"+
                                        "date INTEGER,"+
                                        "duration INTEGER,"+
                                        "data_usage INTEGER,"+
                                        "presentation INTEGER,"+
                                        "numberlabel TEXT,"+
                                        "geocoded_location TEXT,"+
                                        "lookup_uri TEXT,"+
                                        "countryiso TEXT,"+
                                        "transcription TEXT,"+
                                        "subscription_component_name TEXT," +
                                        "name TEXT," +
                                        "matched_number TEXT," +
                                        "subscription_id TEXT," +
                                        "photo_id INTEGER," +
                                        "normalized_number TEXT," +
                                        "is_read INTEGER," +
                                        "type INTEGER,"+
                                        "spam_desc TEXT,"+
                                        "spam_category TEXT)");

        db.execSQL("CREATE TABLE spam_number (_id INTEGER PRIMARY KEY," +
                        "address TEXT,"+
                        "category_1 TEXT,"+
                        "category_2 TEXT,"+
                        "category_3 TEXT,"+
                        "subject TEXT,"+
                        "desc TEXT,"+
                        "etc TEXT)"
        );

        db.execSQL("CREATE TABLE spam_sentence (_id INTEGER PRIMARY KEY," +
                        "sentence TEXT,"+
                        "category_1 TEXT,"+
                        "category_2 TEXT,"+
                        "category_3 TEXT,"+
                        "subject TEXT,"+
                        "desc TEXT,"+
                        "etc TEXT)"
        );
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS spam_sms");
        db.execSQL("DROP TABLE IF EXISTS spam_number");
        db.execSQL("DROP TABLE IF EXISTS spam_sentence");
        onCreate(db);
    }
}
